from serial_operate import get_stand_sql_data
from tools import deal_time, get_previous_15min_time, get_all_meter_addr, execute_sql, make_collect_err_data, \
    modify_centos_current_date_restart

com_name = 'com4'
ip = "192.168.253.113"

# 插入昨天、今天的采集数据,误差数据
print("开始第一步骤")

# 设置站端时间为PC当前时间
modify_centos_current_date_restart(ip)
execute_sql(ip, "TRUNCATE err_voltage_error;")
execute_sql(ip, "TRUNCATE da_voltage_data_temp;")

start, end = get_previous_15min_time()
list_meter_addr = get_all_meter_addr(ip)

start_time = deal_time(start)
end_time = deal_time(end)

collect_ere_data = get_stand_sql_data(start_time, end_time, list_meter_addr[0], com_name, ip)
print(collect_ere_data)

recv_data = collect_ere_data.get("hex_recv")
transformer_address, collect_time, frequency, amplitude, phase, ratio, angle, status = collect_ere_data.get(
    "message_data")

print(transformer_address, collect_time, frequency, amplitude, phase, ratio, angle, status)

# 【检查点1】 采集数据和计算数据全为0，采样数据状态字为类型4，内容=0110
assert frequency == 0
assert amplitude == 0
assert phase == 0
assert ratio == 0
assert angle == 0
assert recv_data[136:144] == '04100110'

# 插入前17、16天的采集数据,误差数据
print("开始第一步骤")
make_collect_err_data(ip, -17, 2, -16, 2)
collect_ere_data = get_stand_sql_data(start_time, end_time, list_meter_addr[0], com_name, ip)
transformer_address, collect_time, frequency, amplitude, phase, ratio, angle, status = collect_ere_data.get(
    "message_data")

# 【检查点2】 采集数据为0，计算数据比差和角差值展示为0
assert frequency == 0
assert amplitude == 0
assert phase == 0
assert ratio == 0
assert angle == 0
